package com.demo.datastructure.linkedList;

/**
 * @description:
 * @author: ljr
 * @time: 2021/4/14 17:55
 */
public class LinkedListDemo2<T>{

    private Node<T> first;

    public boolean addNode(T value){
        boolean result = hastContains(value);
        Node<T> node = new Node<>(value,first);
        first = node;
        return result;
    }

    private boolean hastContains(T value) {
        if(first == null || value == null){
            return false;
        }

        Node<T> node = first;
        do {
            if(node.val == value){
                node.next = node.next.next;
                return true;
            }
        }while ((node = node.next) != null);


        return true;
    }


    private static class Node<T>{
        private final T val;
        private Node<T> next;

        public Node(T val, Node<T> next) {
            this.val = val;
            this.next = next;
        }
    }
}
